<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of cms
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Cms extends MY_Controller {

    function cms() {
        parent :: __construct();
        $this->load->model('cms_model');
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->commoncall->check_admin_login();
    }

    function page($id) {
        $id = intval($id);
        $data['cms']['info'] = $this->cms_model->get_cms($id);
        $data['mode'] = 'VIEW';
        $this->template->title('CMS Management', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_cms', $data);
    }

//--Add New CMS (Subha-17/09/2012)----//    
    function add() {
        $data['cms']['info'] = $this->cms_model->get_cmses();
        $data['mode'] = 'ADD';
        $this->template->title('CMS Management', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_cms', $data);
    }

//--Add /New/Update CMS (Subha-17/09/2012)----//
    function submit($mode, $id) {
        $this->form_validation->set_message('required', '* Required');

        $this->form_validation->set_rules('title', 'Required', 'trim|required||is_unique[cms.title]');
        $this->form_validation->set_rules('meta_title', 'Required', 'trim|required');
        $this->form_validation->set_rules('meta_keyword', 'Required', 'trim|required');
        $this->form_validation->set_rules('meta_description', 'Required', 'trim|required');
        $this->form_validation->set_rules('cms_detail', 'Required', 'trim|required');
        if ($this->form_validation->run() == FALSE) {
            $this->session->set_flashdata('message', 'Error ! Invalid Field data ...');
            $this->add();
        } else {
            $post_data = array(
                'title' => $this->input->post('title'),
                'meta_title' => $this->input->post('meta_title'),
                'meta_keyword' => $this->input->post('meta_keyword'),
                'meta_description' => $this->input->post('meta_description'),
                'description' => $this->input->post('cms_detail'),
                'status' => 51
            );
            if ($post_data) {
                if (trim($mode) == 'add') {
                    $this->db->insert('cms', $post_data);
                }
                if (trim($mode) == 'update') {
                    $this->db->where('id', $id);
                    $this->db->update('cms', $post_data);
                    $this->session->set_flashdata('message', 'Updated successfully..');
                    redirect('admin/cms/page/' . $id);
                }

                $this->session->set_flashdata('message', 'Added successfully..');
                redirect('admin/cms/add');
            }
        }
        if (trim($mode) == 'edit') {
            
        }
    }

}

?>
